﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class ListNote : MonoBehaviour
{

    void Start()
    {
        List<ListDataTest> dataList = new List<ListDataTest>();
        dataList.Add(new ListDataTest { Value = 1 });
        dataList.Add(new ListDataTest { Value = 2 });
        dataList.Add(new ListDataTest { Value = 3 });
        dataList.Add(new ListDataTest { Value = 4 });
        dataList.Add(new ListDataTest { Value = 5 });

        //判断List中是否有 Value == 2 的Key
        int valueToFind = 2;
        bool exists = dataList.Any(dc => dc.Value == valueToFind);

        //查找List中Value == 2 的Key并做处理
        ListDataTest foundItem = dataList.FirstOrDefault(dc => dc.Value == valueToFind);
        if (foundItem != null) { } else { }

        //便利List中大于3的数值
        List<int> ll = new List<int> { 5, 2, 9, 6, 1, 5 };
        //IEnumerable<int> rf = ll.Where(n => n > 3);
        List<int> rf = ll.Where(n => n > 3).ToList();
        int oldNum = ll.Count(n => n > 3);
        foreach (int evenNumber in rf)
        {
            Debug.Log(evenNumber);
        }
    }
}

public class ListDataTest
{
    public int Value;
}
